package com.itzdm.utils;

import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class TimeUtils {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    /**
     * 获取当前时间
     * @return
     */
    public String getCurrentTime() {
        String time = sdf.format(new Date());
        return time;
    }

    /**
     * 获得截止时间
     * @param days
     * @return
     */
    public String getDeadline(Integer days) {
        String time = sdf.format(new Date(System.currentTimeMillis() + days * 3600 * 24 * 1000));
        return time;
    }

    /**
     *
     * @param beginTime
     * @param currentTime
     */
    public Long differenceTime(String beginTime, String currentTime) {
        try {
            Date beginData = sdf.parse(beginTime);
            Date currentData = sdf.parse(currentTime);
            Long beginDataTime = beginData.getTime();
            Long currentDataTime = currentData.getTime();
            Long differenceTime = currentDataTime - beginDataTime;
            return differenceTime;
        } catch (ParseException e) {
            throw new RuntimeException("系统出现bug,请联系管理员！");
        }

    }
}
